import os
import openpyxl
import random

school_name = "某某实验中学"
class_name_dict = {
    "高一年级": ["高一({})班".format(i + 1) for i in range(20)],  # 高一的班级
    "高二年级": ["高二({})班".format(i + 1) for i in range(20)],  # 高二的班级
    "高三年级": ["高三({})班".format(i + 1) for i in range(20)],  # 高三的班级
}

# 创建学校的文件夹
if not os.path.exists(school_name):
    os.makedirs(school_name)


# 创建Excel,生成模拟数据
def mk_excel(excel_name):
    wb = openpyxl.Workbook()
    ws = wb.active
    # 追加一行数据
    ws.append(['姓名', '年龄', '性别', '语文', '英语', '数学', '政治', '历史', '地理'])

    # 批量追加数据
    for i in range(50):
        ws.append(['学生{}'.format(i),
                   random.randint(15, 18),
                   ['男', '女'][random.randint(0, 1)],
                   random.randint(0, 150),
                   random.randint(0, 150),
                   random.randint(0, 150),
                   random.randint(0, 100),
                   random.randint(0, 100),
                   random.randint(0, 100)
                   ])
    wb.save(excel_name)


# 创建高一年级每个班的模拟数据
for i in class_name_dict.keys():
    for class_name in class_name_dict.get(i):
        # 创建班级文件夹
        if not os.path.exists("{}/{}".format(school_name, i)):
            os.makedirs("{}/{}".format(school_name, i))

        # excel名称
        excel_name = "{}.xlsx".format(class_name)
        temp_excel_name = "{}/{}/{}".format(school_name, i, excel_name)
        # 如果有则删除
        if os.path.exists(temp_excel_name):
            os.remove(temp_excel_name)
        # 生成模拟数据
        print(temp_excel_name)
        mk_excel(temp_excel_name)
